<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to CodeIgniter</title>

<style type="text/css">

body {
 background-color: #fff;
 margin: 40px;
 font-family: Lucida Grande, Verdana, Sans-serif;
 font-size: 14px;
 color: #4F5155;
}

a {
 color: #003399;
 background-color: transparent;
 font-weight: normal;
}

h1 {
 color: #444;
 background-color: transparent;
 border-bottom: 1px solid #D0D0D0;
 font-size: 16px;
 font-weight: bold;
 margin: 24px 0 2px 0;
 padding: 5px 0 6px 0;
}

code {
 font-family: Monaco, Verdana, Sans-serif;
 font-size: 12px;
 background-color: #f9f9f9;
 border: 1px solid #D0D0D0;
 color: #002166;
 display: block;
 margin: 14px 0 14px 0;
 padding: 12px 10px 12px 10px;
}
</style>
<script type="text/javascript" src="<?php echo base_url();?>js/fcookie/flashcookie.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/fcookie/Rookie.js?rookie.swf"></script>
<script type="text/javascript">
function onFlashCookieReady(cookie){
//	cookie.set('test', 'I am not from a "cookie" :) ')
//	alert(cookie.get('test'));
//	cookie.del('test');
//	alert(cookie.get('test'));
//	cookie.clear(); //删除全部cookie
}
Rookie(function(){
	/*
	写入键值示例，第一个参数是键名，第二个参数是键值，键值支持以下多种数据格式：
	Number、String、Array、JSON、Date 
	*/
	this.write("myID","rukey67");//键值为字符串格式
	this.write("rukey",{local:"广州",sex:"male"});//键值为JSON式
	this.write("somedata",[234,534523,234234]);//键值为数组
	this.write("createTime",new Date());//键值为时间格式
	
	/*  读取一个键值，如果过期或者未设置，返回 undefined;
		判断是否有可用数据可以通过以下方式判断：
	    if(this.read("abc")){ some code;  }
	或：if(this.read("abc")==undefined){ some code; }	
	*/
	var r=this.read("myID");	//读取键名为 myID 的数据并赋值给 r
	alert(r);
	this.clear("myID");//删除键名为 netease 的本地数据;
	
	
	/***************华丽分隔线*****************************
	
	写入键值时可以带一个json格式的可选参数，包含两个可选属性:
	crossBrowser：布尔值，是否跨浏览器，缺省值为true允许跨浏览器；
	expire：整型数值，以天为单位的过期时间，缺省值为0，永不过期；
	
	使用示例如下：
	*/
	
	this.write("netease","My company",{crossBrowser:false,expire:30});
	
	/* 调试
		运行此页面，可以在IE9/Firefox/Safari/Opera/Chrome 调试工具的 控制台面板查看调试信息
		ie9      自带工具 developer tools，   按 F12 键启动 
		Firefox  附加组件 firebug，           按 F12 键启动
		opera10  自带工具 dragonfly           按 ctrl+shift+i 启动
		Safari4  自带工具                     按 ctrl+alt+c 启动
		Chrome   自带工具（和Safari的极类似） 按 ctrl+shift+i 启动
	
	
	存储路径：
		Windows 95/98/ME/2000/XP
		c:/Documents and Settings/username/Application Data/Macromedia/Flash 
		Player/#SharedObjects

		Windows Vista/Windows 7:
		c:/Users/username/AppData/Roaming/Macromedia/Flash Player/#SharedObjects

		Macintosh OS X:
		/Users/username/Library/Preferences/Macromedia/Flash 
		Player/#SharedObjects/web_domain/path_to_application/application_name/obje
		ct_name.sol

		Linux/Unix:
		/home/username/.macromedia/Flash_Player/#SharedObjects/web_domain/path_to_
		application/application_name/object_name.sol
		
	Good luck！
	*/
});
</script>
</head>
<body>

<h1>Welcome to CodeIgniter!</h1>

<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>


<p><br />Page rendered in {elapsed_time} seconds</p>

<!-- 测试 -->
<?php
function my_echo($var='') {
	echo $var,'<br/>';
}
$arr = array(
	'hello',
	42,
	array(1,'two'),
	'apple'
);
$type = array(
	'n' =>'床上用品',
	array('k'=>'材料','t'=>1,'v'=>'纯棉,亚麻,贡缎'),
	array('k'=>'床尺寸','t'=>1,'v'=>'1.2~1.35m,1.5m,1.8m,2.0m'),
	array('k'=>'套件','t'=>1,'v'=>'三件套,四件套,六件套,九件套,十件套')
);
my_echo(count($type));
$string = serialize($type);//序列化
my_echo($string);

$newarr = unserialize($string);//反序列化
print_r($newarr);
my_echo($newarr[1]['k']);

$string = json_encode($arr);//数组转JSON
my_echo($string);

$newarr = json_decode($string);//JSON转数组
print_r($newarr);
?>
<br/>
<?php
//递归测试
$rows = array(
    array(
        'id' => 1,
        'name' => 'dev',
        'parentid' => 0
    ),
    array(
        'id' => 2,
        'name' => 'php',
        'parentid' => 1
    ),
    array(
        'id' => 3,
        'name' => 'smarty',
        'parentid' => 2
    ),
    array(
        'id' => 4,
        'name' => 'life',
        'parentid' => 0
    ),
    array(
        'id' => 5,
        'name' => 'pdo',
        'parentid' => 2
    ),
    array(
        'id' => 6,
        'name' => 'pdo-mysql',
        'parentid' => 5
    ),
    array(
        'id' => 7,
        'name' => 'java',
        'parentid' => 1
    )
);

function findChild(&$arr,$id){
	$childs=array();
	foreach ($arr as $k =>$v){
		if($v['parentid']== $id){
			$childs[]=$v;
		}
	}
	return $childs;
}

function build_tree($rows,$id){
	$childs=findChild($rows,$id);
	if(empty($childs)){
		return null;
	}
	foreach ($childs as $k => $v){
		$rescurTree=build_tree($rows,$v['id']);
		if( null != $rescurTree){
			$childs[$k]['childs']=$rescurTree;
		}
	}
	return $childs;
}
$tree=build_tree($rows,0);
//echo memory_get_usage();
print_r($tree);

$items = explode(':','text:z',2);
echo count($items);
echo '<br/>',$items[0],'<br/>',$items[1],'<br/>';

$aaa = array(1=>'是',0=>'否');
my_echo(json_encode($aaa));
$aaa = '{"1":"是","0":"否"}';
print_r(json_decode($aaa));

echo false == null;
echo 0 == false;
echo '' == false;
echo 0 == '';
?>
<br/>
<?php if(isset($r_message)) echo $r_message;?>
<br/>
<img id="captcha" src="<?php echo site_url('captcha/mixed'),'?',time();?>"/><a href="javascript:refresh();">看不清</a>
<form method="post" action="<?php echo site_url('welcome/test');?>">
	<input type="text" name="captcha"/>
	<input type="submit" value="验证"/>
</form>
<script>
	function refresh(){
		var captcha = document.getElementById('captcha');
		captcha.src = captcha.src.substring(0,captcha.src.indexOf('?')+1)+new Date().getTime(); 
	}
</script>
</body>
</html>